package cn.com.infinitus.uits.api;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import cn.com.infinitus.uits.auto.uits.BaseDao;

/**
 * 
 * @author 潘科材
 * 获取功能下载情况数据
 */
@Controller
@RequestMapping("/getDownLoadData")
public class GetDownLoadData {
	
	public GetDownLoadData(){
		
	}
	@RequestMapping(value = "/data", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public @ResponseBody String getData(HttpServletRequest request) throws UnsupportedEncodingException{
		SimpleDateFormat sdf_d = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdf_m = new SimpleDateFormat("yyyy-MM");
		BaseDao baseDao= new BaseDao();
		baseDao.openSession();
		//获取数据 固定取当前数据
		Date d = new Date();
		String the_month=sdf_m.format(d);
		String the_day  =sdf_d.format(d);
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("the_month", the_month) ;
		params.put("the_day", the_day) ;
		List<Map<String,Object>> relist = baseDao.query("GET_DOWNLOAD_DATA_ALL", params);
		baseDao.closeSession();
		JSONObject jo = new JSONObject();
		jo.put("resp_code", "00000") ;
		jo.put("resp_desc", "OK") ;
		jo.put("data_list", relist) ;
		
		return String.format("%s(%s)", request.getParameter("callback"), jo.toJSONString());
	}
}
